
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
class MyStore {
  static MyStore instance = new MyStore();

  // 链接的wss地址
  SharedPreferences prefs;

  MyStore({SharedPreferences prefs1}){
    prefs = prefs1;
  }
 
  Map globalData = {};
  List<Color> themeList = [
    Colors.blue,
    Colors.red,
    Colors.pink,
    Colors.purple,
    Colors.deepPurple,
    Colors.indigo,
    Colors.blue,
    Colors.lightBlue,
    Colors.cyan,
    Colors.teal,
    Colors.green,
    Colors.lightGreen,
    Colors.lime,
    Colors.yellow,
    Colors.amber,
    Colors.orange,
    Colors.deepOrange,
    Colors.brown,
    Colors.blueGrey
  ];

  static MyStore getInstance() {
    return instance;
  }

  setGlobal (String name, dynamic data) {
    instance.globalData[name] = data;
  }

  getGlobal (String name) {
    return instance.globalData[name];
  }

  getData (String name) {
    var datastr = instance.prefs.getString(name);
    if (datastr == '' || datastr == null) {
      return null;
    }
    var data = json.decode(datastr);
    return data;
  }

  delData (String name) {
    instance.prefs.remove(name);
  }

  setData (String name, Map data) {
    var datastr = json.encode(data);;
    instance.prefs.setString(name, datastr);
  }
  _prefs () => instance.prefs;
}